#!/usr/bin/env bash

OS_NAME=`uname`
version=${1}

if [ -z ${version} ]; then
    echo "Usage: ./build.sh [version]"
    exit 1
fi

bin_file="worm_access"

rm ${bin_file}
rm ${bin_file}.${version}.tar.gz

# 编译
go build -o ${bin_file} main.go

# 打包
mkdir -p tmp/conf

cp conf/config.conf tmp/conf/config.conf
cp conf/server.pem tmp/conf/server.pem
cp conf/privkey.pem tmp/conf/privkey.pem

cp toolbox/control.sh tmp/control.sh
cp ${bin_file} tmp/${bin_file}

cd ./tmp
tar -czf ${bin_file}.${version}.${OS_NAME}.tar.gz *
cd ..
cp ./tmp/${bin_file}.${version}.${OS_NAME}.tar.gz .

rm -rf tmp